package com.qf.cx.simplenms.reader.tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qf.cx.simplenms.reader.model.AntennaModel;

public class ReaderTags {

	// ant -> tid -> tag
	private Map<AntennaModel, Map<String, AntennaTag>> map = new HashMap<>();

	public void add(AntennaTag newTag) {
		map.putIfAbsent(newTag.getAntenna(), new HashMap<>());
		AntennaTag oldTag = map.get(newTag.getAntenna()).get(newTag.getTid());
		if (oldTag == null) {
			map.get(newTag.getAntenna()).put(newTag.getTid(), newTag);
		} else {
			oldTag.mergeStatistic(newTag.getStatistic());
		}
	}

	public List<AntennaTag> getTags() {
		List<AntennaTag> list = new ArrayList<>();
		Collection<Map<String, AntennaTag>> values = map.values();
		for (Map<String, AntennaTag> e : values) {
			list.addAll(e.values());
		}
		return list;
	}

}
